#ifndef MACHINE_H
#define MACHINE_H

#include "virtio.h"
#include "riscv_cpu.h"

typedef struct VirtMachineParams {
    CharacterDevice * console;
    BlockDevice * drive;
    char * kernel;
    uint64_t ram_size;
    BOOL real_time;
} VirtMachineParams;

typedef struct RISCVMachine {
    /* DEVICE */
    CharacterDevice *cs;
    VIRTIODevice *console;
    VIRTIODevice *drive;
    /* CPU */
    RISCVCPUState *cpu_state;
    /* MEM */
    PhysMemoryMap *mem_map;
    uint64_t ram_size;
    /* RTC */
    BOOL rtc_real_time;
    uint64_t rtc_start_time;
    uint64_t timecmp;
    /* PLIC */
    uint32_t plic_pending_irq, plic_served_irq;
    IRQSignal plic_irq[32];
} RISCVMachine;

RISCVMachine * machine_init (const VirtMachineParams *p);
void raise_timer_interrupt (RISCVMachine *m);
#endif